﻿Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports Spring.Context
Imports Spring.Context.Support
Imports Spring.Objects.Factory
Imports Spring.Objects.Factory.Config
Imports Spring.Objects.Factory.Support
Imports Spring.Testing.NUnit
Imports System.Net.Mail
Imports System.IO


'Namespace Fgv.SigaDois.Testes
Public MustInherit Class TesteInjecaoDependenciaSpring
    Inherits AbstractDependencyInjectionSpringContextTests


    Public Sub New()
        ' Seta para false por causa da propriedade TestContext que nao eh uma dependencia injetada pelo Spring.
        DependencyCheck = False
    End Sub

    Private testContextInstance As TestContext

    ''' <summary>
    '''Gets or sets the test context which provides
    '''information about and functionality for the current test run.
    '''obs: Gerado pelo VisualStudio
    '''</summary>
    Public Property TestContext() As TestContext
        Get
            Return testContextInstance
        End Get
        Set(ByVal value As TestContext)
            testContextInstance = value
        End Set
    End Property

    <TestInitialize()> _
    Public Overridable Sub Initialize()
        Me.applicationContext = GetContext(ContextKey)
        InjectDependencies()
        Try
            OnSetUp()
        Catch ex As Exception
            logger.[Error]("Setup error", ex)
            Throw
        End Try
    End Sub

    <TestCleanup()> _
    Public Overridable Sub Finnalize()
        Try
            OnTearDown()
        Catch ex As Exception
            logger.[Error]("OnTearDown error", ex)
        End Try
    End Sub

    Protected Overrides Sub Finalize()
        ' Instantiate a new instance of MailMessage
        'Dim mMailMessage As New MailMessage()

        'Try
        '    ' Set the sender address of the mail message
        '    mMailMessage.From = New MailAddress("siga@fgv.br")
        '    ' Set the recepient address of the mail message
        '    mMailMessage.To.Add(New MailAddress("lsantana@fgv.br"))

        '    ' Set the subject of the mail message
        '    mMailMessage.Subject = "BASE.Finalize  MyClassInitialize " & My.Computer.Name & " - " & My.User.Name
        '    ' Set the body of the mail message
        '    mMailMessage.Body = "BASE.Finalize Verificando o MyClassInitialize. Hora de envio : " & Now.ToShortTimeString

        '    ' Set the format of the mail message body as HTML
        '    mMailMessage.IsBodyHtml = True
        '    ' Set the priority of the mail message to normal
        '    mMailMessage.Priority = MailPriority.Normal

        '    ' Instantiate a new instance of SmtpClient
        '    Dim mSmtpClient As New SmtpClient()
        '    mSmtpClient.Host = "smtpapp.fgv.br"
        '    mSmtpClient.Port = 25
        '    ' Send the mail message
        '    mSmtpClient.Send(mMailMessage)
        'Catch ex As Exception

        'End Try


        Dim _testRun As TestRun
        Try
            Dim _arquivos() As String = Directory.GetFiles("C:\projetos\SigaDois\Web\SRC\IWI\TestResults\")
            For Each _arquivo In _arquivos
                Try
                    _testRun = TRXSerializer.DESSerialize(_arquivo)
                    TRXLogger.Log(_testRun)
                Catch ex As Exception

                End Try
            Next
        Catch ex As Exception

        End Try

        MyBase.Finalize()
    End Sub

End Class
'End Namespace